/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 22, 2011 5:58:07 PM
 */
package carrello.model.entitydao;
import java.util.Set;
import java.util.List;
import carrello.model.entities.*;
import static carrello.util.EntityManagerUtil.getEntityManager;
public class CategoryDAO {
    
    public void create(Category c)
    {
        getEntityManager().store(c);
    }
    
    public void update(Category c)
    {
        getEntityManager().update(c);
    }

    public void createAll(Set<Category> c)
    {
        getEntityManager().storeAll(c);
    }
    
    public Category getById(int id)
    {
        return Category.getCategoryById(id);
    }
    
    public Category getByName(String name)
    {
        return Category.getCategoryByName(name);
    }
    
    /**
     * Returns the id of the category based on its name
     * @param name The name of the category
     * @return The id of the category
     */
    public int getId(String name)
    {
        return Category.getID(name);
    }
    
    public List<Category> getAll()
    {
        return Category.getAllCategories();
    }
    
    /**
     * Get All the attributes belonging to a specific categoryId
     * @param cid  The category id
     * @return List of attributes
     */
    public List<Attribute> getAttributes(int cid)
    {
        return Category.getAttributesById(cid);
    }
    
    public void delete(Category c)
    {
        getEntityManager().remove(c);
    }
    
       public void deleteAll(Set<Category> c)
    {
        getEntityManager().removeAll(c);
    }
}
